package day06;

import day06.dto.Store;

import java.util.Set;
import java.util.TreeSet;

/**
 * @Auther: sky
 * @Date: 2019/2/28 23:46
 * @Description:
 */
public class CompareTest {

    public static void main(String[] args) {
        // 先用TreeSet按自定义排序规则排序并控制size大小,再转为有序List遍历进行其它操作或处理
        Set<Store> storeSet = new TreeSet<Store>(new StoreComparator());
        storeSet.add(new Store(1, 0));
        storeSet.add(new Store(2, 1));
        storeSet.add(new Store(5, 1));
        storeSet.add(new Store(9, 2));
        storeSet.add(new Store(3, 0));
        storeSet.add(new Store(6, 0));
        storeSet.add(new Store(4, 1));
        storeSet.add(new Store(7, 2));
        storeSet.add(new Store(0, 0));
        storeSet.add(new Store(8, 1));
        int sgrade = -1;
        // 打印排序后的结果
        for (Store s : storeSet) {
            if (sgrade != s.getSgrade() && -1 != sgrade) {
                System.out.println("------------------------------");
            }
            System.out.println(s);
            sgrade = s.getSgrade();
        }
    }
}
